part of markdown;

/// 主要是在gaia刚加载时，把Folder中的信息转换到内存里
extension Transfer on Directory {
  bool get isMarkdown => name.contains(".") && !name.startsWith(".");

  Markdown get md {
    List out = [];

    // 读取text数据
    String top = name.split(".")[1];
    out.add("top:$top");

    // 大剪切
    List<String> body = mdFile.readAsStringSync().split("\n");
    body = body._cut(Rule.bold);
    body = body._cut(Rule.wiki);
    body = body._cut(Rule.link);

    // 替换图片
    for (final text in body) {
      if (text.isPhoto) {
        String filename = Rule.photo.firstMatch(text)!.group(1)!;
        final file = findPhoto(filename);
        out.add({
          "text": file.name,
          "data": BsonBinary.from(file.readAsBytesSync()),
        });
      } else {
        out.add(text);
      }
    }

    return out;
  }
}
